package com.corechina.apex_osswords.controller;


import com.corechina.apex_osswords.common.Response;
import com.corechina.apex_osswords.common.ShiroUtils;
import com.corechina.apex_osswords.common.SysLog;
import com.corechina.apex_osswords.domain.dto.CoreEquipmentTypeDto;
import com.corechina.apex_osswords.service.ICoreEquipmentCheckService;
import com.corechina.apex_osswords.service.ICoreEquipmentTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 设备分类表 前端控制器
 * </p>
 *
 * @author cc
 * @since 2022-12-09
 */

@Api(tags = "设备分类")
@RestController
@RequestMapping("/core/equipmentType")
public class CoreEquipmentTypeController {

    @Autowired
    private ICoreEquipmentTypeService iCoreEquipmentTypeService;

    @Autowired
    private ICoreEquipmentCheckService iCoreEquipmentCheckService;

    @ApiOperation("新增")
    @SysLog("新增设备分类")
    @PostMapping("/add")
    public Response add(@RequestBody CoreEquipmentTypeDto coreEquipmentTypeDto) {
        return iCoreEquipmentTypeService.add(coreEquipmentTypeDto);
    }

    @ApiOperation("编辑")
    @SysLog("编辑设备分类")
    @PutMapping("/update")
    public Response update(@RequestBody CoreEquipmentTypeDto coreEquipmentTypeDto) {
        return iCoreEquipmentTypeService.update(coreEquipmentTypeDto);
    }

    @ApiOperation("删除")
    @SysLog("删除设备分类")
    @DeleteMapping("/del")
    public Response del(Integer id) {
        if (iCoreEquipmentTypeService.removeById(id)) {
            return Response.ok();
        }
        return Response.error();
    }

    @ApiOperation("列表")
    @GetMapping("/getList")
    public Response getList(String name, Integer pageIndex, Integer pageSize) {
        return iCoreEquipmentTypeService.getList(name, pageIndex, pageSize);
    }

    @ApiOperation("详情")
    @GetMapping("/getOne")
    public Response getOne(Integer id) {
        return Response.ok(iCoreEquipmentTypeService.getById(id));
    }

    @ApiOperation("根据类型获取检查项列表")
    @GetMapping("/getCheckList")
    public Response getCheckList(Integer equipmentType, String name) {
        return iCoreEquipmentCheckService.getList(equipmentType, name, ShiroUtils.getSeeAll().equals(1) ? null : ShiroUtils.getEnterpriseId());
    }
}

